package cn.net.xyan.easy.webapp.base.entity;

import cn.net.xyan.easy.spring.jpa.utils.sequence.TableSequenceGenerator;
import cn.net.xyan.easy.webapp.base.entity.format.ArchiveIDFormat;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;


import javax.persistence.*;
import java.util.Date;

/**
 * Created by xiashenpin on 16/1/17.
 */
@Entity
@Table(name = "t_archive")
@Inheritance(strategy= InheritanceType.JOINED)
@DiscriminatorColumn(name="type",discriminatorType = DiscriminatorType.STRING)
public class Archive {

    public final static String ArchiveID = "cn.net.xyan.easy.webapp.base.entity.archive.id";

    String archiveId;
    String fileName;
    String describe;
    String mimetype;
    byte[] data;
    long size;
    Date createDate;

    @Column(name = "fileName",nullable = false,length = 1024)
    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    @Lob
    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
        if (data!=null)
            setSize(data.length);
    }

    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Id
    @Column(name = "id",unique = true,updatable = false,nullable = false,length = 32)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = ArchiveID)
    @GenericGenerator(name = ArchiveID,
            strategy = TableSequenceGenerator.STRATEGY,
            parameters = {
                    //@Parameter(name = "format", value = "LD0000000")
                    @Parameter(name = "formatClass", value = ArchiveIDFormat.FormatClass)
            })
    public String getId() {
        return archiveId;
    }

    public void setId(String id) {
        this.archiveId = id;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    //@Sequence(value = "cn.net.xyan.easy.webapp.base.entity.archive.mimetype",format = ArchiveIDFormat.class)
    @Column(name = "mime",updatable = false,length = 32)
    public String getMimetype() {
        return mimetype;
    }

    public void setMimetype(String mimetype) {
        this.mimetype = mimetype;
    }
}
